package com.sample.mockito.test;

import com.sample.mockito.Person;
import com.sample.mockito.PersonDao;
import com.sample.mockito.PersonServiceImpl;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.ArrayList;
import java.util.List;

import static org.mockito.Mockito.when;

public class SampleTest03 {

    @InjectMocks
    private static PersonServiceImpl personService;
    @Mock
    private static PersonDao personDao;

    @Before
    public void setUp(){
        MockitoAnnotations.initMocks(this);
    }


    @Test
    public void sampleTest09(){
        List<Person> persons = new ArrayList<Person>();
        Person person = new Person();
        person.setId(3l);
        person.setName("sdfsdf");
        persons.add(person);
        when(personDao.queryAll("test1")).thenReturn(persons);

        List<Person> personst1 = personService.queryAll("test1");
        System.out.println(personst1);

        List<Person> personst2 = personService.queryAll("test2");
        System.out.println(personst2);
    }
}